﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using CreditAgricole.Framework;

namespace CreditAgricole.SPTest.CACustomApprovalTechProc
{
    public sealed partial class CACustomApprovalTechProc : SequentialWorkflowActivity
    {
        #region Fields

        #endregion

        public CACustomApprovalTechProc()
        {
            InitializeComponent();
        }

        public Guid workflowId = default(System.Guid);
        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
        public static DependencyProperty taskOutcomeProperty = DependencyProperty.Register("taskOutcome", typeof(System.String), typeof(CreditAgricole.SPTest.CACustomApprovalTechProc.CACustomApprovalTechProc));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute("Misc")]
        public String taskOutcome
        {
            get { return ((string)(base.GetValue(CreditAgricole.SPTest.CACustomApprovalTechProc.CACustomApprovalTechProc.taskOutcomeProperty))); }
            set { base.SetValue(CreditAgricole.SPTest.CACustomApprovalTechProc.CACustomApprovalTechProc.taskOutcomeProperty, value); }
        }

        private void completeTask1_MethodInvoking(object sender, EventArgs e)
        {

        }

        private void sendEmail1_MethodInvoking(object sender, EventArgs e)
        {
            SPListItem item = onWFActivated.WorkflowProperties.Item;
            sendNotificationEmail.To = "";//item[SPBuiltInFieldId.Author].ToString();
            sendNotificationEmail.Body = "Please approve the document";
        }

        public static DependencyProperty whileNotCompleted_Condition1Event = DependencyProperty.Register("whileNotCompleted_Condition1", typeof(System.EventHandler<System.Workflow.Activities.ConditionalEventArgs>), typeof(CreditAgricole.SPTest.CACustomApprovalTechProc.CACustomApprovalTechProc));

        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        [CategoryAttribute("Handlers")]
        public event EventHandler<ConditionalEventArgs> whileNotCompleted_Condition1
        {
            add
            {
                base.AddHandler(whileNotCompleted_Condition1Event, value);
            }
            remove
            {
                base.RemoveHandler(whileNotCompleted_Condition1Event, value);
            }
        }

        public static DependencyProperty createParallelTaskActivity_Condition1Event = DependencyProperty.Register("createParallelTaskActivity_Condition1", typeof(System.EventHandler<System.Workflow.Activities.ConditionalEventArgs>), typeof(CreditAgricole.SPTest.CACustomApprovalTechProc.CACustomApprovalTechProc));

        public IList approvers = default(System.Collections.IList);

        private void createParallelTaskActivity_Initialized(object sender, EventArgs e)
        {
            // Get approvers from item
            SPListItem item = workflowProperties.Item;
            if (item != null)
            {
                SPFieldUserValueCollection users = SPHelper.GetSPUsers(item, Constants.ParallelApproversField);
                if (users != null) approvers = users.ToList();
            }
        }

        private void createParallelTaskActivity_ChildInitialized(object sender, ReplicatorChildEventArgs e)
        {
            SPFieldUserValue user = e.InstanceData as SPFieldUserValue;

        }

        private void createApprovalTask_MethodInvoking(object sender, EventArgs e)
        {

        }

        private void onWFActivated_Invoked(object sender, ExternalDataEventArgs e)
        {
            // Initialize approvers list

        }
    }
}
